﻿Imports System.Data.OleDb
Imports System.Data
Imports System.Configuration
Imports System.Drawing
Imports System.Web.UI
Imports System.Web.UI.WebControls
Public Class ManageUser
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
       
       
    End Sub

    Protected Sub GridView1_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GridView1.RowDataBound
        If e.Row.RowType = DataControlRowType.DataRow Then


            Dim usr As String = e.Row.Cells(0).Text
            If Roles.IsUserInRole(usr, "Admin") Then
                Dim chkb As CheckBox = CType(e.Row.FindControl("chkAdmin"), CheckBox)
                chkb.Checked = True
            End If
        End If
    End Sub

    Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles btnUpdate.Click
        For Each gvrow As GridViewRow In GridView1.Rows
            Dim chk As CheckBox = DirectCast(gvrow.FindControl("chkAdmin"), CheckBox)
            Dim usr As String = gvrow.Cells(0).Text
            If chk IsNot Nothing Then
                If chk.Checked Then
                    If Not Roles.IsUserInRole(usr, "Admin") Then
                        Roles.AddUserToRole(usr, "Admin")
                    End If
                Else
                    If Roles.IsUserInRole(usr, "Admin") Then
                        Roles.RemoveUserFromRole(usr, "Admin")
                    End If
                End If
            End If
        Next
    End Sub
End Class